package com.scut.edu.wanyou.conf;


import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Iterator;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;

/**
 * Description:
 * <p>
 * 通过*.property文件定义的配置信息
 * </p>
 * Configuration.java Create on 2012-4-22 上午7:7:06 
 * @author chenxc
 * @version 1.0
 * Copyright (c) 2012 Company,Inc. All Rights Reserved.
 */
public class Configuration {
	
	/**配置信息容器**/
	private static SharedPreferences sp;
	private static Editor editor;
	
	public Configuration()
	{
		
	}
	public Configuration(Context context){
		//获取SharedPreferences对象 
		Context ctx = context;        
		sp = ctx.getSharedPreferences("properties", Context.MODE_PRIVATE);
		editor = sp.edit();
		//存入数据
		if(sp.getString("username", "none").equals("none"))
		{
			editor.putString("username", "");
			editor.putString("password", "");
			editor.commit();
		}
		
	}
	
	
	
	/**
	 * Description:
	 * <p>根据key值获取配置信息，如果不存在返回defaultVal</p>
	 * Date:2012-6-10
	 * @author chenxc
	 * @param key
	 *        配置信息的key
	 * @param defaultVal
	 *        配置信息的默认值
	 * @return 
	 * @return String
	 */
	public String get(String key , String defaultVal)
	{
		String value = sp.getString(key,defaultVal) ;
		return value;
	}
	
	/**
	 * Description:
	 * <p>根据提供的key和val设置Map</p>
	 * Date:2012-6-10
	 * @author chenxc
	 * @param key
	 *        配置信息的key
	 * @param defaultVal
	 *        配置信息的默认值
	 * @return 
	 * @return String
	 */
	public void set(String key , String val)
	{
		editor.putString(key, val);
		editor.commit();
	}
	
}